package chapter10;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/18 18:33
 */
public class HashMapTest {
    public static void main(String[] args) {
        Random random = new Random(47);
        Map<Integer, Integer> countMap = new HashMap<>();
        for (int i = 0; i < 1000; i++) {
            int num = random.nextInt(4);
            countMap.merge(num, 1, (a, b) -> a + b);
        }

        for (Map.Entry<Integer, Integer> entry : countMap.entrySet()) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }

        Map<Integer, Integer> testMap = new HashMap<>(4);
        testMap.put(1, 1);
        testMap.put(2, 1);
        testMap.put(3, 1);
        testMap.put(4, 1);

        System.out.println("testMap values:" + testMap.values());
    }
}
